package com.hbjycl.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.hbjycl.dao.StudentDao;
import com.hbjycl.entity.Student;
import com.hbjycl.entity.Teacher;




@Repository
@Transactional
public class StudentDaoImpl extends BaseDaoImpl<Student, String> implements StudentDao
{
    @Override
    public boolean isExistByUsername(String username)
    {
        String hql = "from Student student where  student.username  = ?";
        Student student = (Student) getSession().createQuery(hql).setParameter(0, username)
                .uniqueResult();
        if (student != null)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    
    @Override
    public Student getStudentByUsername(String username)
    {
        String hql = "from Student student where student.username = ?";
        return (Student) getSession().createQuery(hql).setParameter(0, username).uniqueResult();
    }
    
    @Override
    public List<Teacher> getTeacherList(String username)
    {
        String hql = "select teacherList from Student where username=?";
        return getSession().createQuery(hql).setParameter(0, username).list();
    }
    
       
    
    @Override
    public boolean deleteStudentTeacher(String studentId)
    {
        String sql = "delete from student_teacher where Teacherlist_id=?";
        int result = getSession().createSQLQuery(sql).setParameter(0, studentId).executeUpdate();
        return result > 0;
    }

    @Override
    public List<Student> getLockedAccounts()
    {
        String hql = "from Student where isAccountLocked=?";
        return getSession().createQuery(hql).setParameter(0, true).list();
    }

}